import {HttpUtil} from "../utils/HttpUtil";
import {CookieUtil} from "../utils/CookieUtil";
import {Base64} from 'js-base64';
import {CONST} from "../base/constant";


export const loginAction = (username,password) => {

    const url = CONST.API_PREFIX + "/user";

    CookieUtil.createCookie('token',Base64.encode(username + ':' + password),1);

    return new Promise(function (resove,reject) {
        HttpUtil.get(url).then(function (txt) {
            const res = JSON.parse(txt);
            resove(res);
        }).catch(function (err) {
            reject(err);
        });
    })

};